<div id="tb<?php echo $uniqid;?>" class="datagrid-toolbar">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td><SELECT v-model="agentLevel" @change="teamlistSearch" class="textbox-text validatebox-text">
				<OPTION value="0">所有等级</OPTION>
				<OPTION value="0" disabled="disabled"> --------</OPTION>
				<template v-for="(vo,index) in levelList">
					<OPTION :value="vo.level">{{vo.name}}</OPTION>
				</template>
			</SELECT>
			</td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" @click="teamlistReset" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重置</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td>
				<select  v-model="keywordsType" class="forminput inputstyle textbox-text validatebox-text" style="width:80px">
					<option value="id">会员ID</option>
					<option value="nickname">会员昵称</option>
					<option value="phone">手机号</option>
				</select></td>
			<td><input  v-model="keywords"  style="width:120px" type="text"
					   class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" @click="teamlistSearch" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span
					class="l-btn-text">查询</span></span></a></td>

			<td><a href="javascript:void(0);" onclick="teamlistExport()" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-xiazai"></i><span
					class="l-btn-text">导出团队信息</span></span></a></td>
		</tr>
		</tbody>
	</table>
</div>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'west',collapsed:false" style="width:180px;border:none;">
		<div class="con"  style="-moz-user-select:none;">
			<table id="memberteamcount"></table>
		</div>
	</div>
	<div data-options="region:'center'">
		<div class="con"  style="-moz-user-select:none;">
			<table id="memberteamlist"></table>
		</div>
	</div>
</div>

<script>
	Vm['team<?php echo $uniqid;?>'] = new Vue({
		el: '#tb<?php echo $uniqid;?>',
		data: {
			agentLevel: 0,
			keywordsType: 'id',
			keywords: '',
			levelList: JSON.parse('<?php echo addslashes($levelList);?>'),
		},
		methods: {
			teamlistSearch(){
				teamlistSearch();
			},
			teamlistReset(){
				this.agentLevel = 0;
				$("#memberteamcount").datagrid('unselectAll');
				teamlistSearch();
			}
		}
	});
	var teamlistExport = function () {
		showLoading('.con');
		$.post('/admin/member/exportteamlist', {
			id: '<?php echo $id;?>',
			level: $('#memberteamcount').datagrid('getSelected') && $('#memberteamcount').datagrid('getSelected').level || 0,
			agent_level: Vm['team<?php echo $uniqid;?>'].agentLevel,
			keywordsType: Vm['team<?php echo $uniqid;?>'].keywordsType,
			keywords: Vm['team<?php echo $uniqid;?>'].keywords,
		}, function (data) {
			hideLoading();
			if (parseInt(data.ret) === 0) {
				$.messager.show({
					title: '提示',
					msg: data.msg,
					timeout: 3000,
					showType: 'slide'
				});
				eventmaterialDownload(data.data);
			} else {
				$.messager.alert('提示', data.msg, 'warning');
			}
		}, 'json').fail((response)=> {
			hideLoading();
			$.messager.alert('提示', response.responseText, 'warning');
		});
	};

	var memberteamSearch = function () {
		var height = 560 - 96;
		var width =  180 - 2;
		$("#memberteamcount").datagrid({
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: false,//如果为true，则显示一个行号列。
			pagination: false,//是否显示分页
			method: 'post',
			idField: 'id',
			url: '/admin/member/team',
			queryParams: {id: '<?php echo $id;?>'},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			columns: [[
				{field:'level',title:'分组',width:'30%',formatter:function (value,rowData,rowIndex){
						return value + '组';
					}},
				{field:'counter',title:'人数',align:'right',width:'50%',formatter:function (value,rowData,rowIndex){
						return value + '人';
					}},
			]],
			onClickRow: function (rowIndex, rowData) {
				teamlistSearch();
			}
		});
	};
	var memberteamEdit = function (id) {
		let rowId = id || ($('#memberteamlist').datagrid('getSelected') && $('#memberteamlist').datagrid('getSelected').id);
		if (rowId) {
			$("#memberdlg").dialog({
				title: '编辑信息',
				closed: false,
				width: 840,
				height: 560,
				cache: false,
				href: '/admin/member/edit?id=' + rowId,
				modal: true,
				buttons: [{
					text: '保存',
					id: 'membersubmit',
					iconCls: 'icon-ok',
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#memberdlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要编辑的行！', 'warning');
		}
	};
	var teamlistSearch = function (level) {
		var height= 560 - 133;
		var width =  759 - 2;
		$("#memberteamlist").datagrid({
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: false,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'id',
			sortOrder: 'desc',
			idField: 'id',
			url: '/admin/member/teamlist',
			queryParams: {
				id: '<?php echo $id;?>',
				level: $('#memberteamcount').datagrid('getSelected') && $('#memberteamcount').datagrid('getSelected').level || 0,
				agent_level: Vm['team<?php echo $uniqid;?>'].agentLevel,
				keywordsType: Vm['team<?php echo $uniqid;?>'].keywordsType,
				keywords: Vm['team<?php echo $uniqid;?>'].keywords,
			},
			fitColumns: false,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			columns: [[
				{field:'id',title:'ID',width:'10%'},
				{field:'avatar',title:'头像',width:'5%',formatter:function (value,rowData,rowIndex){
						return value ? "<img height='25px' style='border-radius: 5px;' src='"+value+"'>" : '';
					}},
				{field:'nickname',title:'用户',width:'15%'},
				{field:'parent_member_id',title:'老师',width:'10%'},
				{field:'phone',title:'手机号',width:'15%'},
				{field:'level_info',title:'身份',width:'10%', formatter(value, rowData){
						return value ? value.name : '普通会员';
					}},
				{field:'money',title:'余额',width:'8%',sortable:true},
				{field:'score',title:'积分',width:'8%',sortable:true},
				{field:'total_income',title:'累计佣金',width:'8%',sortable:true},
				{field:'total_consume',title:'消费金额',width:'8%',sortable:true},
				{field:'child_user_count',title:'团队人数',width:'8%',formatter:function (value,rowData,rowIndex){
						return value>0 ? "<a style='cursor: pointer' href='javascript:void(0)' onclick='memberTeams(\"" + rowData.nickname + '\",' + rowData.id + ")'>" + value + "</a>" : 0;
					}},
				{field:'team_consume',title:'团队业绩',width:'8%',sortable:true},
				{
					field:'status',title:'状态',width:'8%',formatter:function (value,rowData,rowIndex){
						let status_test = '';
						switch (value) {
							case 'normal':
								status_test = '正常';
								break;
							case 'frozen':
								status_test = '冻结';
								break;
							case 'lock':
								status_test = '锁定';
								break;
							default:
								status_test = '未知';
						}
						return status_test;
					}
				},
				{field:'created_at',title:'加入时间',width:'18%',sortable:true},
			]],
			onDblClickRow: function (index, field) {
				memberteamEdit();
			}
		});
	};
	memberteamSearch();
	teamlistSearch();
</script>
